<?php
/**
 * Project: AIGC
 * Author: moufer <moufer@163.com>
 * Date: 2024/7/20 00:00
 */

namespace module\chat\front\table;

use module\chat\model\Category;
use mof\enum\StatusEnum;
use mof\front\Table;
use mof\utils\DictArray;
use mof\utils\ElementData;

class CategoryTable extends Table
{
    protected string $serverBaseUrl = '/{module}/admin/{table}';
    protected string $sortField     = 'listorder';
    protected string $sort          = 'desc';
    protected bool $showSearch      = false;

    protected ElementData $typeListEd;

    protected function init(): void
    {
        parent::init();
        $typeList = Category::getTypeList();
        $this->typeListEd = DictArray::make($typeList)->toElementData();

        //tabs
        $this->tabProp = 'type';
        $this->tabs = $this->typeListEd->toTabs('label', 'value');
        $this->activeTab = array_keys($typeList)[0];
    }

    protected function columnId(): array
    {
        return [
            "prop"  => 'id',
            "label" => 'ID',
        ];
    }

    protected function columnListorder(): array
    {
        return [
            "prop"  => 'listorder',
            "label" => '排序',
        ];
    }

    protected function columnType(): array
    {
        return [
            "prop"    => 'type',
            "label"   => '类型',
            "search"  => true,
            "type"    => "select",
            "options" => $this->typeListEd->toSelectOptions(),
        ];
    }

    protected function columnName(): array
    {
        return [
            "prop"   => 'name',
            "label"  => '名称',
            "search" => true,
            "width"  => "*"
        ];
    }

    protected function columnIcon(): array
    {
        return [
            "prop"  => 'icon',
            "label" => '图标',
            "width" => "80",
            "type"  => "image"
        ];
    }


    protected function columnStatus(): array
    {
        return [
            "prop"    => 'status',
            "label"   => '状态',
            "type"    => "select",
            "search"  => true,
            "options" => StatusEnum::toDict()->toElementData()->toSelectOptions(),
        ];
    }

    protected function columnRemark(): array
    {
        return [
            "prop"  => 'remark',
            "label" => '备注',
        ];
    }

    protected function columnCreateAt(): array
    {
        return [
            "prop"  => 'create_at',
            "label" => '新建时间',
            "type"  => "datetime"
        ];
    }
}